package com.chinasofti.manager.service;

import com.chinasofti.manager.dao.StudentDao;
import com.chinasofti.manager.domain.Student;

public class StudentService {

    StudentDao StudentDao = new StudentDao();

    public void deleteStudentById(String id){
        StudentDao.deleteStudentById(id);
    }

    //判断学号是否存在
   public boolean isExists(String id){//返回值为true ， 代表id不存在
       boolean exists = false ;
       //判断数组中是否有这个id
       int index = StudentDao.getIndex(id);
       if (index == -1){
             exists = true ;
       }
       return exists;
   }

   public boolean addStudent(Student stu){
       return StudentDao.addStudent(stu);
   }
   public Student[] findAllStudent(){
        Student[] allStudent =   StudentDao.findAllStudent();
        boolean flag = false ;
        for (int i = 0;i<allStudent.length;i++){
            Student stu = allStudent[i];
            if (stu!= null){
                flag = true;
                break;
            }
        }
        if (flag){
            return allStudent;
        }else{
            return null;
        }
   }

    public void updateStudent(String updateId, Student newStu) {
        StudentDao.updateStudent(updateId,newStu);
    }
}
